home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Language / Compiler / option.c < prev    next >
C/C++ Source or Header  |  1990-08-16  |  2KB  |  91 lines

  1. /*
  2.  * @(#)option.c    1.4  9/24/87
  3.  */
  4. #include "types.h"
  5. #include "flags.h"
  6. #include "assert.h"
  7. #include "option.h"
  8. #include "trace.h"
  9.  
  10. int         optioninvokequeue = 1,
  11.         optionallocateregisters = 1,
  12.         optioncomment = 1,
  13.         optionnilspace = 1,
  14.         optionlocals = 1,
  15.         optionknowct = 1,
  16.         optionview = 2,
  17.         optioninline = 0,
  18.         optiondebugstack = 0,
  19.         optioncreateonstack = 1;
  20.  
  21. typedef struct {
  22.   char *name;
  23.   int  *flag;
  24. } flagTable, *flagTablePtr;
  25.  
  26. flagTable optionTable [] = {
  27.   "invokequeue", &optioninvokequeue,
  28.   "allocateregisters", &optionallocateregisters,
  29.   "comment", &optioncomment,
  30.   "nilspace", &optionnilspace,
  31.   "locals", &optionlocals,
  32.   "knowct", &optionknowct,
  33.   "view", &optionview,
  34.   "inline", &optioninline,
  35.   "debugstack", &optiondebugstack,
  36.   "createonstack", &optioncreateonstack,
  37.   NULL, 0
  38. };
  39.  
  40. extern void toLower();
  41.  
  42. extern char *find();
  43.  
  44. parseOptionFlag(f)
  45. register char *f;
  46. {
  47.   char *comma, *equals;
  48.   register flagTablePtr tp;
  49.   int value;
  50.  
  51.   assert(*f == '-'); f++;
  52.   assert(*f == 'O'); f++;
  53.   toLower(f);
  54.   while (f && *f) {
  55.     comma = find(f, ',');
  56.     if (comma != NULL) *comma = '\0';
  57.     equals = find(f, '=');
  58.     if (equals == NULL) {
  59.       value = 1;
  60.     } else {
  61.       value = atoi(equals+1);
  62.       if (value < 0) value = 1;
  63.       *equals = '\0';
  64.     }
  65.     for (tp = &optionTable[0]; tp->name; tp++) {
  66.       if (!strcmp(f, tp->name)) {
  67.     *tp->flag = value;
  68.     break;
  69.       }
  70.     }
  71.     if (tp->name == NULL) {
  72.       fprintf(stdout, "Unknown option name \"%s\"\n", f);
  73.       return(0);
  74.     }
  75.     f = (comma == NULL ? NULL : comma + 1);
  76.   }
  77.   return(1);
  78. }
  79.  
  80. void initializeOption()
  81. {
  82.   register flagTablePtr tp;
  83.   
  84.   IFTRACE(help, 1) {
  85.     fprintf(stdout, "Option\t\tValue\n");
  86.     for (tp = &optionTable[0]; tp->name; tp++) {
  87.       fprintf(stdout, "\"%s\" -->\t%d\n", tp->name, *tp->flag);
  88.     }
  89.   }
  90. }
  91.